package com.apes.fn.server.pickUpCar.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.ApesBean;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.jpa.tuple.date.DateTime;
import com.apes.framework.util.ApesConst;
import com.apes.framework.util.DateUtil;
import com.apes.scm.masterdata.frame.model.Dept;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;

/**
 * @Classname KeyNumber
 * @Description 存储钥匙号
 * @Date 2020/1/15 18:18
 * @Created by wsj
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = KeyNumber.CONST_TABLE_NAME, indexes = {@Index(columnList = "dept_id,key_card",unique = true)})
public class KeyNumber implements ApesBean {
    public static final String CONST_TABLE_NAME = "fn_key_number";
    @Id
    @Column(name = "id")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "钥匙号表",prefix="2",padding = 5)
    @Comment("ID")
    private String id;

    @Column(name = "key_card", length = 3)
    @Comment("钥匙号")
    private int keyCard;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "dept_id", referencedColumnName = "id")
    @Comment("门店")
    private Dept dept;

    @Column(name = "valid", nullable = false, columnDefinition = ApesConst.FIELD_BOOLEAN_TRUE)
    @Comment("有效标记")
    private boolean valid = true;

    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @DateTime
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "update_date", insertable = false)
    @Comment("修改日期")
    private Date updateDate;
}
